<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        {{message}}
        <br />
        <button @click="btn">点击修改</button>
        <br /> {{obj}}
        <button @click="btnobj">点击修改obj的值</button>
    </div>
    <script>
        new Vue({
            el: "#app",
            data: {
                message: "数据",
                obj: {
                    name: "zzl",
                    age: 29,
                },
            },
            methods: {
                btn() {
                    this.message = "修改了";
                },
                btnobj() {
                    this.obj = {
                        name: "zl",
                        age: 18,
                    };
                },
            },
            watch: {
                message: function(newA, newB) {
                    console.log(newA, newB);
                },
                obj: {
                    handler(newA, newB) {
                        console.log(newA, newB);
                    },
                    deep: true, //深层次监听
                },
            },
        });
    </script>
</body>

</html>